package com.itheima.myreflect2.Student.convertedio;

import java.io.*;

/**
 * @program: Myset
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-16 11:34
 **/
public class ConvertedDemo6 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        wirteToLocal();
        readToInner();
        return;

    }

    private static void readToInner() throws IOException, ClassNotFoundException {
        //读取到内存
        ObjectInputStream oos = new ObjectInputStream(new FileInputStream("e.txt"));
        Object obj;
        while ((obj  = oos.readObject()) != null){
            System.out.println(obj);
       }
        oos.close();
    }

    private static void wirteToLocal() throws IOException {
        Student stu1 = new Student("粤汉路1","101");
        Student stu2 = new Student("粤汉路2","102");
        Student stu3 = new Student("粤汉路3","103");

        //写到本地
        ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream("e.txt"));
        ois.writeObject(stu1);
        ois.writeObject(stu2);
        ois.writeObject(stu3);
        //也可以往里面装一个对象

        ois.close();
    }
}
